package controller;

/**
 * Felugró ablakok sablonjául szolgál
 *
 */
public class PopUp extends javax.swing.JDialog {
	protected static final long serialVersionUID = 1797503938140699597L;
	
	public boolean isOK;

	protected javax.swing.JComboBox addComboBox;
	private javax.swing.JPanel addPanel;
    protected javax.swing.JButton cancelButton;
    private javax.swing.JPanel centerPanel;
    private javax.swing.JLabel commonLabel;
    protected javax.swing.JTextField commonTextField;
    private javax.swing.JPanel commonTextFieldPanel;
    private javax.swing.JPanel inputNumberSetterPanel;
    protected javax.swing.JTextField inputTextField;
    private javax.swing.JLabel inputsLabel;
    private javax.swing.JLabel messageLabel;
    protected javax.swing.JRadioButton offRadioB;
    private javax.swing.JButton okButton;
    protected javax.swing.JRadioButton onRadioB;
    private javax.swing.ButtonGroup switchButtonGroup;
    private javax.swing.JPanel switchPanel;
    private javax.swing.JLabel switchSetterLabel;
	
	public static final int ADD_BLOCK = 101;
	public static final int ADD_WIRE = 102;
	public static final int INPUT_SETTER= 103;
	public static final int SEQUENCE_SETTER = 104;
	public static final int MEMORY_GETTER_SETTER = 105;
	public static final int STEP = 106;
	public static final int SWICH_PROPERTIES = 107;
	public static final int COMPOSITE_SETTER = 108;
	
	public static final int AND_INDEX = 0;
	public static final int OR_INDEX = 1;
	public static final int NOT_INDEX = 2;
	public static final int SWITCH_INDEX = 3;
	public static final int LED_INDEX = 4;
	public static final int SEQUENCE_GENERATOR_INDEX = 5;
	public static final int OSCILLOSCOPE_INDEX = 6;
	public static final int COMPOSITE_INDEX = 7;
	public static final int COMPOSITEPORT_INDEX = 8;

    /** Creates new form PopUp */
    protected PopUp(java.awt.Frame owner, String message) {
    	super(owner, "Figyelem!", true);
    	
    	this.isOK = false;
    	
        initComponents();
        this.messageLabel.setText(message);
        
        this.setBounds(300, 200, this.getWidth(), this.getHeight());
        
        this.centerPanel.setBounds(0, 0, 0, 0);
        this.centerPanel.setLayout(new java.awt.BorderLayout());      
        pack();
    }
    
    protected PopUp(java.awt.Frame owner, String message, int type) {
        this(owner, message);
    	
        if(type == PopUp.ADD_BLOCK){
        	this.centerPanel.add(this.addPanel);
        	this.messageLabel.setText("Add Block");
        	
        	this.addComboBox.addItem("AND gate");
        	this.addComboBox.addItem("OR gate");
        	this.addComboBox.addItem("NOT gate");
        	this.addComboBox.addItem("Switch");
        	this.addComboBox.addItem("LED");
        	this.addComboBox.addItem("Sequence Generator");
        	this.addComboBox.addItem("Oscilloscope");
        	this.addComboBox.addItem("Composite");	
        	this.addComboBox.addItem("Composite Port");
        	
        }
        if(type == PopUp.INPUT_SETTER){
        	this.centerPanel.add(this.inputNumberSetterPanel);
        	if(message == null || message.isEmpty()){
        		this.messageLabel.setText("Setting Input Number");
        	}        	
        }
        if(type == PopUp.SEQUENCE_SETTER){
        	this.centerPanel.add(this.commonTextFieldPanel);
        	this.commonLabel.setText("Sequence: ");
        	this.commonTextField.setText("");
        	if(message == null || message.isEmpty()){
        		this.messageLabel.setText("Sequence Generator Properties");
        	}
        }
        if(type == PopUp.MEMORY_GETTER_SETTER){
        	this.centerPanel.add(this.commonTextFieldPanel);
        	this.commonLabel.setText("Memory: ");
        	this.commonTextField.setText("");
        	if(message == null || message.isEmpty()){
        		this.messageLabel.setText("Oscilloscope Properties");
        	}
        }
        if(type == PopUp.STEP){
        	this.centerPanel.add(this.commonTextFieldPanel);
        	this.commonLabel.setText("Step: ");
        	this.commonTextField.setText("");
        	if(message == null){
        		this.messageLabel.setText("");
        	}
        }
        if(type == PopUp.SWICH_PROPERTIES){
        	this.centerPanel.add(this.switchPanel);
        	this.switchButtonGroup.add(onRadioB);
        	this.switchButtonGroup.add(offRadioB);
        	if(message == null || message.isEmpty()){
        		this.messageLabel.setText("Switch Properties");
        	}
        }
        if(type == PopUp.COMPOSITE_SETTER){
        	this.centerPanel.add(this.commonTextFieldPanel);
        	this.commonLabel.setText("Composite path: ");
        	this.commonTextField.setText("");
        	if(message == null || message.isEmpty()){
        		this.messageLabel.setText("Set Composite's path");
        	}
        }        
        
        pack();
    }

    private void initComponents() {

        addPanel = new javax.swing.JPanel();
        addComboBox = new javax.swing.JComboBox();
        inputNumberSetterPanel = new javax.swing.JPanel();
        inputsLabel = new javax.swing.JLabel();
        inputTextField = new javax.swing.JTextField();
        commonTextFieldPanel = new javax.swing.JPanel();
        commonLabel = new javax.swing.JLabel();
        commonTextField = new javax.swing.JTextField();
        switchPanel = new javax.swing.JPanel();
        switchSetterLabel = new javax.swing.JLabel();
        onRadioB = new javax.swing.JRadioButton();
        offRadioB = new javax.swing.JRadioButton();
        switchButtonGroup = new javax.swing.ButtonGroup();
        messageLabel = new javax.swing.JLabel();
        okButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        centerPanel = new javax.swing.JPanel();

        javax.swing.GroupLayout addPanelLayout = new javax.swing.GroupLayout(addPanel);
        addPanel.setLayout(addPanelLayout);
        addPanelLayout.setHorizontalGroup(
            addPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(addPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(addComboBox, 0, 209, Short.MAX_VALUE)
                .addContainerGap())
        );
        addPanelLayout.setVerticalGroup(
            addPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(addPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(addComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        inputsLabel.setText("Inputs: ");

        inputTextField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        inputTextField.setText("2");
        inputTextField.setMinimumSize(null);

        javax.swing.GroupLayout inputNumberSetterPanelLayout = new javax.swing.GroupLayout(inputNumberSetterPanel);
        inputNumberSetterPanel.setLayout(inputNumberSetterPanelLayout);
        inputNumberSetterPanelLayout.setHorizontalGroup(
            inputNumberSetterPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(inputNumberSetterPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(inputsLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(inputTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        inputNumberSetterPanelLayout.setVerticalGroup(
            inputNumberSetterPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(inputNumberSetterPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(inputNumberSetterPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(inputsLabel)
                    .addComponent(inputTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        commonLabel.setText("Label: ");

        javax.swing.GroupLayout commonTextFieldPanelLayout = new javax.swing.GroupLayout(commonTextFieldPanel);
        commonTextFieldPanel.setLayout(commonTextFieldPanelLayout);
        commonTextFieldPanelLayout.setHorizontalGroup(
            commonTextFieldPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(commonTextFieldPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(commonLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(commonTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        commonTextFieldPanelLayout.setVerticalGroup(
            commonTextFieldPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(commonTextFieldPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(commonTextFieldPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(commonLabel)
                    .addComponent(commonTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        
        switchSetterLabel.setText("DefaultState: ");

        onRadioB.setText("On");

        offRadioB.setText("Off");

        javax.swing.GroupLayout switchPanelLayout = new javax.swing.GroupLayout(switchPanel);
        switchPanel.setLayout(switchPanelLayout);
        switchPanelLayout.setHorizontalGroup(
            switchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(switchPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(switchSetterLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(switchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(offRadioB)
                    .addComponent(onRadioB))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        switchPanelLayout.setVerticalGroup(
            switchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(switchPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(switchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addGroup(switchPanelLayout.createSequentialGroup()
                        .addComponent(onRadioB)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(offRadioB))
                    .addComponent(switchSetterLabel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        setResizable(false);

        messageLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        messageLabel.setText("message");

        okButton.setText("  OK  ");
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout centerPanelLayout = new javax.swing.GroupLayout(centerPanel);
        centerPanel.setLayout(centerPanelLayout);
        centerPanelLayout.setHorizontalGroup(
            centerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 292, Short.MAX_VALUE)
        );
        centerPanelLayout.setVerticalGroup(
            centerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 68, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(centerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(messageLabel, javax.swing.GroupLayout.Alignment.CENTER, javax.swing.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.CENTER, layout.createSequentialGroup()
                        .addComponent(okButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(messageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(centerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(okButton)
                    .addComponent(cancelButton))
                .addContainerGap())
        );

        pack();
    }
    protected void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
    	this.isOK = true;
        this.setVisible(false);
    }
    
    protected void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
        this.dispose();
    }
}
